package com.haodai.agency.utils;

import android.content.Context;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by fanday on 2015/8/13.
 */
public class AssetsUtils {

    /**
     * 将assets文件内的城市文件转为String
     *
     * @param context
     * @param fileName assets文件内文件的名字
     * @return
     */
    public static String getData(Context context, String fileName) {
        try {
            InputStreamReader inputReader = new InputStreamReader(context.getResources()
                    .getAssets().open(fileName));
            BufferedReader bufReader = new BufferedReader(inputReader);
            String line = "";
            StringBuffer Result = new StringBuffer();
            while ((line = bufReader.readLine()) != null)
                Result.append(line);
            return Result.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 通过文件名获取mipmap中图片的id
     * @param imageName
     * @param context
     * @return
     */
    public static int getMipmapId(String imageName,Context context) {
        int resId = context.getResources().getIdentifier(imageName, "mipmap", context.getPackageName());
        return resId;
    }
}
